<%@page import="com.wanmait.hotelManage.vo.Pager"%>
<%@page import="java.util.List"%>
<%@page import="com.wanmait.hotelManage.vo.RoomType"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
    String path=request.getContextPath();
    List<RoomType> roomTypes=(List<RoomType> )request.getAttribute("roomTypes");
    %>
<table id="tt" class="result-tab" width="100%">
                        <tr>
                            <th class="tc" width="5%"><input class="allChoose" name="" type="checkbox"></th>
                           <!--  <th>序号</th> -->
                            <th>ID</th>
                            <th>标题</th>
                            <th>图片</th>
                            <th>简介</th>
                            <th>是否热门</th>
                            
                            <th>原价</th>
                            <th>现价</th>
                            <th>操作</th>
                        </tr>
                       <%  
                       	if(roomTypes!=null){
                        for(int i=0;i<roomTypes.size();i++){
                        	RoomType roomType=roomTypes.get(i);
                        	/* out.print(roomType); */
                        	%>
                        	
                        	<tr id="tr<%=roomType.getId()%>">
                        	
                               <td class="tc"><input data-id="<%=roomType.getId() %>" class="choose" name="id[]" value="59" type="checkbox"></td>
                               <%-- <td><%=i+1 %></td>  --%>
                               <td><%=roomType.getId() %></td>
                               <td><%=roomType.getTitle() %></td>
                               <td><img width="100" src="<%=path%>/static/images/<%=roomType.getPic() %>"></td>
                               <td style="width:500px;"><%=roomType.getDescription() %></td>
                               <td><%=roomType.getHot()?"热门":"非热门" %></td>
                                <td><%=roomType.getPrice() %></td>
                                <td><%=roomType.getDiscountPrice() %></td>
                               
                               <td class="tt">
                                   <a class="link-update" href="<%=path%>/manage/RoomTypeServlet?action=updateInit&id=<%=roomType.getId()%>">修改</a>
                                   <a class="link-del"  id="del<%=roomType.getId()%>" href="#">删除</a>
                               </td>
                           </tr>
                        <% 	
                        }
                       }
                       %>
                    </table>
                    
                     <!-- 显示数字 -->
						<%Pager pager = (Pager)request.getAttribute("pager"); %>
						<div style="text-align: center;">
						<%
						int start = 1;
						int end = pager.getPageCount();
						if(pager.getPageCount()>5)
						{
							start = pager.getPageNo()-2<1?1:pager.getPageNo()-2;
							end = start+4;
							if(end>pager.getPageCount())
							{
								end = pager.getPageCount();
								start = end-4;
							}
						}
						
						for(int i=start;i<=end;i++){
							if(pager.getPageNo()!=i){
							%>
							[<a class="number" href="javascript:void(0)"><%=i %></a>]
							<%
						}else{
							%>
							[<a class="aaa" style="color: red;" href="javascript:void(0)"><%=i %></a>]
							<%
						}
					}

					%>
						</div>
	<!-- 显示数字的结束 -->
                    
                    
<script>
	$(function() {
		$(".number").click(function(){
			$(".number").css("color","black");
			$(this).css("color","red");
			var n = $(this).html();
			
			$.ajax({
				url:"<%=path%>/manage/RoomTypeServlet?action=getRoomTypes",
				data:{"pageNo":n},
				success:function(msg){
					$(".result-content").html(msg);
				}
			})
			
		})
		<%-- var path="<%=path%>"; --%>
		//删除
		/* $("#tt").on("click",".link-del",function() { */
			var del=function(){
				if(!window.confirm("你确定要删除吗")){
					return false;
				}
				var id=$(this).attr("id").substring(3);
				$.ajax({
					url:"<%=path%>/manage/RoomTypeServlet?action=delete",
					data:{id:id},
					success:function(msg){
						$("#tr"+id).remove();
					}
				});
			}
			$(".link-del").bind("click",del);
			$(".link-del").live("click",del);
		
		//全选
		$(".allChoose").click(function() {
			$(".choose").prop("checked",$(this).prop("checked"));
		})
		//批量删除
		$("#batchDel").click(function() {
			var arr=[];
			$(".choose:checked").each(function() {
				var id=$(this).data("id");
				arr.push(id);
			});
			if(arr.length>0){
				$.ajax({
					url:"<%=path%>/manage/RoomTypeServlet?action=batchDelete",
					data:{ids:arr.toString()},
					success:function(){
						for(var i=0;i<arr.length;i++){
							$("#tr"+arr[i]).remove();
						}
					}
				})
			}
		});
		
		<%-- $("input[id^='sort']").blur(function() {
			var sort=$(this).val();
			var id=$(this).attr("id").substring(4);
			$.ajax({
				url:"<%=path%>/manage/productTypeServlet?action=updateSort",
				data:{id:id,sort:sort}
			});
		}); --%>
		
	});
</script>